package com.chf.job.service.impl;

import com.chf.job.dao.EducationMapper;
import com.chf.job.pojo.Education;
import com.chf.job.service.EducationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EducationServiceImpl implements EducationService {
    @Autowired
    private EducationMapper educationMapper;
    /**
     * 根据简历id查询教育经历
     * @param id
     * @return
     */
    @Override
    public List<Education> getByResumeId(Integer id) {
        return educationMapper.getByResumeId(id);
    }

    /**
     * 更新添加教育背景
     * @param education
     * @return
     */
    @Override
    public int updateEducation(Education education) {
        if (education.getId() == null) {
            Education newEducation = new Education();
            newEducation.setResumeId(education.getResumeId());
            newEducation.setSchoolName(education.getSchoolName());
            newEducation.setMajor(education.getMajor());
            newEducation.setRecord(education.getRecord());
            newEducation.setStartYear(education.getStartYear());
            newEducation.setEndYear(education.getEndYear());
            return educationMapper.insertSelective(newEducation);
        }
        Education newEducation = new Education();
        newEducation.setId(education.getId());
        newEducation.setSchoolName(education.getSchoolName());
        newEducation.setMajor(education.getMajor());
        newEducation.setRecord(education.getRecord());
        newEducation.setStartYear(education.getStartYear());
        newEducation.setEndYear(education.getEndYear());
        return educationMapper.updateByPrimaryKeySelective(education);
    }

    /**
     * 根据id删除教育背景
     * @param educationId
     * @return
     */
    @Override
    public int deleteById(Integer educationId) {
        return educationMapper.deleteByPrimaryKey(educationId);
    }
}
